package com.ruoyi.mall.controller;

import java.util.List;

import com.ruoyi.mall.entity.MallPackageRecord;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.service.IMallPackageRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 购买优惠包记录表Controller
 * 
 * @author ruoyi
 * @date 2020-05-28
 */
@Controller
@RequestMapping("/mall/record")
public class MallPackageRecordController extends BaseController
{
    private String prefix = "mall/record";

    @Autowired
    private IMallPackageRecordService mallPackageRecordService;

    @RequiresPermissions("mall:record:view")
    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询购买优惠包记录表列表
     */
    @RequiresPermissions("mall:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MallPackageRecord mallPackageRecord)
    {
        startPage();
        List<MallPackageRecord> list = mallPackageRecordService.selectMallPackageRecordList(mallPackageRecord);
        return getDataTable(list);
    }

    /**
     * 导出购买优惠包记录表列表
     */
    @RequiresPermissions("mall:record:export")
    @Log(title = "购买优惠包记录表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MallPackageRecord mallPackageRecord)
    {
        List<MallPackageRecord> list = mallPackageRecordService.selectMallPackageRecordList(mallPackageRecord);
        ExcelUtil<MallPackageRecord> util = new ExcelUtil<MallPackageRecord>(MallPackageRecord.class);
        return util.exportExcel(list, "record");
    }

    /**
     * 新增购买优惠包记录表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存购买优惠包记录表
     */
    @RequiresPermissions("mall:record:add")
    @Log(title = "购买优惠包记录表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MallPackageRecord mallPackageRecord)
    {
        return toAjax(mallPackageRecordService.insertMallPackageRecord(mallPackageRecord));
    }

    /**
     * 修改购买优惠包记录表
     */
    @GetMapping("/edit/{packageRecordId}")
    public String edit(@PathVariable("packageRecordId") Long packageRecordId, ModelMap mmap)
    {
        MallPackageRecord mallPackageRecord = mallPackageRecordService.selectMallPackageRecordById(packageRecordId);
        mmap.put("mallPackageRecord", mallPackageRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存购买优惠包记录表
     */
    @RequiresPermissions("mall:record:edit")
    @Log(title = "购买优惠包记录表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MallPackageRecord mallPackageRecord)
    {
        return toAjax(mallPackageRecordService.updateMallPackageRecord(mallPackageRecord));
    }

    /**
     * 删除购买优惠包记录表
     */
    @RequiresPermissions("mall:record:remove")
    @Log(title = "购买优惠包记录表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mallPackageRecordService.deleteMallPackageRecordByIds(ids));
    }
}
